package indi.zhang.rabbitmq.listener;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.yomahub.tlog.core.mq.TLogMqConsumerProcessor;
import com.yomahub.tlog.core.mq.TLogMqRunner;
import com.yomahub.tlog.core.mq.TLogMqWrapBean;
import indi.zhang.mq.MessageContent;
import indi.zhang.mq.api.Consumer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;

@Slf4j
public abstract class RabbitMqTlogListener implements Consumer {
    @RabbitHandler
    public void process(String msg) {
        try {
            TLogMqWrapBean<MessageContent> tLogMqWrap = JSONObject.parseObject(msg, new TypeReference<TLogMqWrapBean<MessageContent>>(){});
            TLogMqConsumerProcessor.process(tLogMqWrap, new TLogMqRunner<MessageContent>() {
                @Override
                public void mqConsume(MessageContent o) {
                    //业务操作
                    deal(o);
                }
            });
        }catch (Exception e) {
            e.printStackTrace();
        }
    }
}
